]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
JS: migrate from the global `window` to `globalThis`
authorAndy Holmes <andrew.g.r.holmes@gmail.com>
Thu, 23 Apr 2020 23:06:36 +0000 (16:06 -0700)
committerAndy Holmes <andrew.g.r.holmes@gmail.com>
Mon, 27 Apr 2020 02:07:02 +0000 (19:07 -0700)
As of mozjs68 (gjs-1.64) `globalThis` is recommended over `window` and
it makes more sense in this context anyways. Migrate the few instances
of `window` we use and adjust the eslint configuration.

`window` will continue to resolve to `globalThis`, so this won't affect
extensions or other downstream users.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2322

closes #2322

js/ui/environment.js
js/ui/lookingGlass.js
js/ui/main.js
lint/eslintrc-gjs.yml
subprojects/extensions-app/js/main.js

index 7a96d948004c5341243335ffec177f3500073baf..4a123140248d8bc78174680a76b90a6a731bdc79 100644 (file)
@@ -245,16 +245,15 @@ function _loggingFunc(...args) {
 }
 
 function init() {
-    // Add some bindings to the global JS namespace; (gjs keeps the web
-    // browser convention of having that namespace be called 'window'.)
-    window.global = Shell.Global.get();
+    // Add some bindings to the global JS namespace
+    globalThis.global = Shell.Global.get();
 
-    window.log = _loggingFunc;
+    globalThis.log = _loggingFunc;
 
-    window._ = Gettext.gettext;
-    window.C_ = Gettext.pgettext;
-    window.ngettext = Gettext.ngettext;
-    window.N_ = s => s;
+    globalThis._ = Gettext.gettext;
+    globalThis.C_ = Gettext.pgettext;
+    globalThis.ngettext = Gettext.ngettext;
+    globalThis.N_ = s => s;
 
     GObject.gtypeNameBasedOnJSPath = true;
 
index 838a0c833a4f4fddba35c3d34f6adb92fb138d0c..6ef8ddae38cfdee16701cd2dd3236a569c63a79e 100644 (file)
@@ -37,8 +37,8 @@ const LG_ANIMATION_TIME = 500;
 
 function _getAutoCompleteGlobalKeywords() {
     const keywords = ['true', 'false', 'null', 'new'];
-    // Don't add the private properties of window (i.e., ones starting with '_')
-    const windowProperties = Object.getOwnPropertyNames(window).filter(
+    // Don't add the private properties of globalThis (i.e., ones starting with '_')
+    const windowProperties = Object.getOwnPropertyNames(globalThis).filter(
         a => a.charAt(0) != '_'
     );
     const headerProperties = JsParse.getDeclaredConstants(commandHeader);
index 3fcc8b2852c67624b5437db300ef2b375b488754..f1f069af42f06380c84925678cf105527451f901 100644 (file)
@@ -125,8 +125,8 @@ function _sessionUpdated() {
 
 function start() {
     // These are here so we don't break compatibility.
-    global.logError = window.log;
-    global.log = window.log;
+    global.logError = globalThis.log;
+    global.log = globalThis.log;
 
     // Chain up async errors reported from C
     global.connect('notify-error', (global, msg, detail) => {
index fec07a4095a1a34a6898122a97d6a03f62d6890e..3fa6b86b58065a825bc423775c95f3c92318c308 100644 (file)
@@ -218,12 +218,12 @@ globals:
   ARGV: readonly
   Debugger: readonly
   GIRepositoryGType: readonly
+  globalThis: readonly
   imports: readonly
   Intl: readonly
   log: readonly
   logError: readonly
   print: readonly
   printerr: readonly
-  window: readonly
 parserOptions:
   ecmaVersion: 2019
index 00b6c047dbb2bd30b35df182989ca274c8efcfcd..25804e5ba0e552066f763b91e20f90b78eec8de9 100644 (file)
@@ -476,7 +476,7 @@ var ExtensionRow = GObject.registerClass({
 function initEnvironment() {
     // Monkey-patch in a "global" object that fakes some Shell utilities
     // that ExtensionUtils depends on.
-    window.global = {
+    globalThis.global = {
         log(...args) {
             print(args.join(', '));
         },